package com.tjmc.nsia.core.dto.resp;

import cn.hutool.core.collection.CollectionUtil;
import lombok.Data;

import java.util.List;
import java.util.Objects;

/**
 * @author Luc
 * @version 1.0
 * @date 2024-07-11 19:27
 */
@Data
public class NsiaExamQuestionAnswer {

    private Integer examId;

    private String key;

    private String examTitle;

    private List<NsiaExamQuestion> questions;

    private Double totalScore;

    private Double passScore;

    private int questionSize;

    public NsiaExamQuestionAnswer() {
    }

    public NsiaExamQuestionAnswer(String key, String examTitle, List<NsiaExamQuestion> questions) {
        this.key = key;
        this.examTitle = examTitle;
        this.questions = questions;
        this.computeScore();
    }

    private void computeScore() {
        if(!CollectionUtil.isEmpty(this.questions)) {
            this.questionSize = this.questions.size();
            double totalScore = 0;
            for(NsiaExamQuestion question : this.questions) {
                if(!Objects.isNull(question.getScore())) {
                    totalScore += question.getScore();
                }
            }
            this.totalScore = totalScore;
            this.passScore = totalScore * 0.6;
        }
    }


}
